<?php
	class dathangchitietdb
	{
		public function Add($MaDatHang, $MaSanPham, $SoLuong)
		{
			$sql = "INSERT INTO `tbl_dathang_chitiet`(`MaDatHang`, `MaSanPham`, `SoLuong`)
					VALUES($MaDatHang, $MaSanPham, $SoLuong)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaDatHang)
		{
			$sql = "DELETE FROM `tbl_dathang_chitiet` WHERE MaDatHang = $MaDatHang";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaChiTiet, $SoLuong)
		{
			$sql = "UPDATE `tbl_nhomhang` SET SoLuong=$SoLuong WHERE MaChiTiet = $MaChiTiet"; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
		public function GetList($MaChiTiet, $MaDatHang, $SoLuong)
		{
			$sql = " SELECT * FROM `tbl_dathang`, `tbl_dathang_chitiet` WHERE tbl_dathang.MaDatHang = tbl_dathang_chitiet.MaDatHang ";
			if($MaDatHang!="")
				$sql .= " AND tbl_dathang_chitiet.MaDatHang = $MaDatHang ";
			if($MaChiTiet!="")
				$sql .= " AND tbl_dathang_chitiet.MaChiTiet = $MaChiTiet ";
			
			if($SoLuong!="")
				$sql .= " AND tbl_dathang_chitiet.SoLuong = $SoLuong ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		public function Find($MaChiTiet, $MaDatHang, $SoLuong)
		{
			$sql = "SELECT * FROM `tbl_dathang`, `tbl_dathang_chitiet` WHERE tbl_dathang.MaDatHang = tbl_dathang_chitiet.MaDatHang ";
			if($MaNhomHang!="" || $TenNhomHang!="")
				$sql = " SELECT * FROM `tbl_dathang`, `tbl_nguoidung` WHERE tbl_dathang.MaNguoiDung = tbl_nguoidung.MaNguoiDung OR  tbl_dathang_chitiet.MaDatHang = $MaDatHang OR  tbl_dathang_chitiet.MaChiTiet = $MaChiTiet OR tbl_dathang_chitiet.SoLuong = $SoLuong";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
	}
?>